package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ShoppingCartController {
    @Autowired
    private CartService cartService;
    //加入购物车
    @PostMapping("/cart/add")
    public ResultInfo addCart(@RequestBody Cart cart){//接收参数
        //调用service
        Cart cart1= cartService.addCart(cart);
        //返回结果
        return ResultInfo.success(cart1);

    }
    //查看购物车
    @GetMapping("/cart/list")
    public ResultInfo look(){
        //调用service
        List<Cart> cartList=cartService.look();
        //返回结果
        return ResultInfo.success(cartList);

    }
    //移除购物车
    @PostMapping("/cart/sub")
    public ResultInfo removeCart(@RequestBody Cart cart){//接收参数
        //调用service
        Cart cart1= cartService.removeCart(cart);
        //返回结果
        return ResultInfo.success(cart1);

    }
    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo deleteAll(){
        //调用service
    cartService.deleteAll();
    return ResultInfo.success();
    }
}
